/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package org.kz.shange.security;

import com.htkj.vdr.common.utils.MyLogger;
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;
import org.kz.shange.common.KzTemplate;
import org.kz.shange.models.Author;
import org.kz.shange.models.IAuthorDao;

/**
 *
 * @author Administrator
 */
@ManagedBean(name = "logonMgr")
@RequestScoped
public class LogonMgr extends KzTemplate implements Serializable {
    @ManagedProperty(name = "authorDao", value = "#{authorDao}")
    private IAuthorDao authorDao;
    private String account;
    private String password;
    public void logon(){
        MyLogger.info(this.getClass(), String.format("登录信息：帐号/密码：%s/%s",this.account,this.password));
        Author aut=this.authorDao.findAuthor(account);
        MyLogger.info(this.getClass(),aut.toString());
        
        if((aut!=null)&&(aut.getPassword().equals(this.password))){
            super.saveLogonUserToSession(aut);
        }else{
            super.addErrorMessage("用户名或密码不正确！");
        }
    }

//<editor-fold defaultstate="collapsed" desc="property">
    public String getAccount() {
        return account;
    }
    
    public void setAccount(String account) {
        this.account = account;
    }

    public IAuthorDao getAuthorDao() {
        return authorDao;
    }

    public void setAuthorDao(IAuthorDao authorDao) {
        this.authorDao = authorDao;
    }
    
    public String getPassword() {
        return password;
    }
    
    public void setPassword(String password) {
        this.password = password;
    }
//</editor-fold>
}
